#ifndef SEMAFORO_H_
#define SEMAFORO_H_

#include "../common/Object.h"
#include <iostream>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/types.h>

class Semaphore:public Object
{
private:
	union semnum
	{
		int val;
		struct semid_ds* buf;
		ushort* array;
	};

	int id;
	int valorInicial;

	void init ();

public:
	Semaphore ( std::string nombre,char id, int valorInicial);
	virtual ~Semaphore();

	/**
	 *
	 */
	void dec ();

	/**
	 *
	 */
	void inc ();

	/**
	 *
	 */
	bool tryDec();

	/**
	 *
	 */
	void destroy ();
};

#endif /* SEMAFORO_H_ */
